package com.cloudxingkong.dianyinke.NewTeacher.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.cloudxingkong.dianyinke.R;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by LeeQ on 2016-5-6.
 */
public class PJGridAdapter extends BaseAdapter {
    private String []imgPaths;
    private LayoutInflater inflater;
    private Context context;
    public PJGridAdapter(String[] imgPaths,Context context) {
        this.context=context;
        inflater=LayoutInflater.from(context);
        this.imgPaths = imgPaths;
    }

    @Override
    public int getCount() {
        return imgPaths==null?0:imgPaths.length;
    }

    @Override
    public Object getItem(int position) {
        return imgPaths[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        NoScrollGVViewHolder holder;
        if (convertView == null) {
            holder=new NoScrollGVViewHolder();
            convertView=inflater.inflate(R.layout.item_pj_gridview,null);
            holder.imageView= (ImageView) convertView.findViewById(R.id.item_pj_gv_img);
            convertView.setTag(holder);
        }else{
            holder= (NoScrollGVViewHolder) convertView.getTag();
        }

        String url=imgPaths[position];

        /*if (getCount() == 1||getCount() == 2 ||getCount()==3|| getCount() == 4) {
            holder.imageView.setLayoutParams(new AbsListView.LayoutParams(100, 100));
        }*/

        ImageLoader.getInstance().displayImage(url, holder.imageView);

        return convertView;
    }

    private class NoScrollGVViewHolder{
        ImageView imageView;
    }
}
